#include "toolhelper.h"
#include "QString"
#include "dateinteger.h"

ToolHelper::ToolHelper()
{
}

QString ToolHelper::GetSubString(QString str, int index, int len)
{
    QString cp = str;
    return cp.remove(index,len);
}

QVariantMap ToolHelper::Convert(QSqlRecord record, QStringList columns)
{
    QVariantMap map;
    if(!columns.contains("*")){
        foreach(QString c,columns)
        {
            map[c]= record.value(c);
        }
    }
    else
    {
        for(int i=0;i<record.count();i++)
        {
            map[record.fieldName(i)]=record.value(i);
        }
    }
    return map;
}

QString ToolHelper::GetDateFilter(QDate fromDate, QDate toDate)
{
    QStringList filter;
    DateInteger fd(fromDate),td(toDate);
    filter.append(" where FDate>="+fd.ToString());
    filter.append(" FDate<="+td.ToString());
    return filter.join(" And ");
}
